// *******************************************************************************************************
// # �ƒ�����
//   �E
//
// *******************************************************************************************************

function GoRstobi(srcType, syubetu, madori, key)
{
	var items = [];
	
	items.push({name:'target_0', value:key});
	items.push({name:'search_type', value:srcType});
	items.push({name:'syubetu' + syubetu, value:'on'});
	
	for(var i in madori){
		items.push({name:'madori' + madori[i], value:'on'});
	}
	//console.dir(items);
	submit('/rstobi/rstobi', 'POST', items);
}

$(function(){
	var isUnderIe6 = uaInfo.isIe && uaInfo.ieVr <= 6,
		isUnderIe7 = uaInfo.isIe && uaInfo.ieVr <= 7;


	/*******************************************************
	 * index heightLine
	 *******************************************************/
	function idxHeightLine(){
		$('.mod_list_title .box_madori .mod_btn').heightLine();
	};


	/*******************************************************
	 * index checkbox
	 *******************************************************/
	function idxCheckBox() {
		var $cls = $('.mod_box_section_bdt .list_title .box_class'),
			$mdr = $('.mod_box_section_bdt .list_title .box_madori'),
			$btn = $('#contentMain .mod_btn_append a');
		
		$cls.find('li').each(function(i){
			var id = $(this).attr('class');
			$(this).find('a').on('click', function(e){
				$cls.find('input').val(id);
				changeSelect();
			});
		});

		$mdr.find('li').each(function(i){
			var id = $(this).attr('class');
			$(this).find('a').on('click', function(e){
				$mdr.find('input').val(id);
				changeSelect();
			});
		});

		function changeSelect(){
			var cls = $cls.find('input').val(),
				mdr = $mdr.find('input').val();
			
			var selclass = null,
		    	selmadori = null;
			
			$cls.find('li').each(function(i){
				if ($(this).hasClass(cls)){
					//$(this).find('a').addClass('active');
					var obj = $(this).find('a');
					obj.addClass('active');
					selclass = obj.attr("id");
					
				} else {
					$(this).find('a').removeClass('active');
				};
			});
			$mdr.find('li').each(function(i){
				if ($(this).hasClass(mdr)){
					//$(this).find('a').addClass('active');
					var obj = $(this).find('a');
					obj.addClass('active');
					selmadori = obj.attr("id");
					
				} else {
					$(this).find('a').removeClass('active');
				};
			});
			if (cls && cls != '' && mdr && mdr != '') {
				$btn.removeClass('mod_btn_disabled');
				$btn.click(function() {
					var url = window.location.pathname + '/' + selclass + selmadori + '/';
					window.location.href = url.replace('//', '/');;
				});
			} else {
				$btn.addClass('mod_btn_disabled');
			};
		};
		changeSelect();
	};


	/*******************************************************
	 * map checkbox
	 *******************************************************/
	function mapCheckBox() {
		var $map = $('#contentMain .map_wrap ul'),
			$iptMap = $('#contentMain .map_wrap input'),
			$btn = $('#contentMain .mod_btn_append li a');

		$map.find('li').each(function(e){
			var id = $(this).attr('class');
			$(this).on('click', function(e){
				$iptMap.val(id);
				changeSelectMap();
			});
		});

		function changeSelectMap(){
			var map = $iptMap.val();

			$map.find('li').each(function(e){
				$(this).removeClass('active');
				if ($(this).hasClass(map)) {
					$(this).addClass('active');
					
					$btn.click(function() {
						
						//新潟
						var idVal = $iptMap.val();
						if(idVal == 'nigata') idVal = 'niigata';
						var url = window.location.pathname + '/' + idVal;
						
						if($(this).attr('id') == 'line')
							url += '/line/';
						
						window.location.href = url.replace('//', '/');
					});
				};
			});
			if (map && map != '') {
				$btn.removeClass('mod_btn_disabled');
			};
		};
		changeSelectMap();
	};

	
	// init
	if ($('#containerInner').hasClass('index')){
		idxHeightLine();
		idxCheckBox();
	};
	if ($('#containerInner').hasClass('map')){
		mapCheckBox();
	};
});